﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using OpenNETCF.Media.WaveAudio;
namespace RecorderSample.Controller
{
  public class AudioItemListPageControler:IDisposable
    {
      public void Dispose()
      {
          _audioPlayer.Dispose();
      }
    //  private WaveOut _audioPlayer;
      private Player _audioPlayer;

      public AudioItemListPageControler()
      {
          _audioPlayer = new Player();
      }
      public void Play(string fileName)
      {
          //Stop();

          //if (Wave.MMSYSERR.NOERROR != _audioPlayer.Play(fileName, 512 * 1024, 0xffff, 0xffff))
          //{
          //    throw new Exception("FAILURE: Failed to play sound");
          //}
          //try
          //{
          //    if (_audioPlayer != null)
          //    {
          //        _audioPlayer.Stop();
          //    }
          //}
          //catch
          //{
          //}
          if (_fileName == fileName && _paused)
          {
              _audioPlayer.Restart();
              _paused = false;

          }
          else
          {
              FileStream fs = new FileStream(fileName, FileMode.Open);
              //if (_audioPlayer != null)
              //{
              //    _audioPlayer.Dispose();
              //}
              //_audioPlayer = new Player();
              _audioPlayer.Play(fs);
          }
      
     

      }
      public void Stop()
      {
       ////   _audioPlayer.BlockDone(IntPtr.Zero);
       //   _audioPlayer.Stop();
          _audioPlayer.Stop();
      }
      private string _fileName;
      private bool _paused;
      public void Pause()
      {
          _paused = true;
          _audioPlayer.Pause();
      }
     
      public void Resume()
      {
          _audioPlayer.Restart();
      }
    }
}
